package com.redrose.videodemo.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;

import java.io.ByteArrayOutputStream;


public class BitmapUtils {
    public Bitmap compressSize(Bitmap bitmap){
        return null;
    }

    /**
     * bitmap 转byte
     * @param data Bitmap
     * @return Bitmap
     */
    public static Bitmap bytesBitmap(byte[] data){
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 5;
        Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,options);
        bitmap = rotateBitmapByDegree(bitmap,90);
        return bitmap;
    }
    /**
     * 将图片旋转多少度
     *
     * @param bm     图片
     * @param degree 旋转角度
     * @return
     */
    public static Bitmap rotateBitmapByDegree(Bitmap bm, int degree) {
        Bitmap returnBm = null;
        Matrix matrix = new Matrix();
        matrix.postRotate(degree);
        try {
            returnBm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(),
                    bm.getHeight(), matrix, true);
        } catch (OutOfMemoryError e) {
        }
        if (returnBm == null) {
            returnBm = bm;
        }
        if (bm != returnBm) {
            bm.recycle();
        }
        return returnBm;
    }
}
